//充值中心
Vue.component('coin', {
	props: [''],
	template:"#coin_template", 
	data: function() {
		return {
			host:globalData.constParam.url.baseUrl,
			url: {
				getWallet:'/api/AppFun/GetWallet', //获取金币信息
				getReChargeData:'/api/AppFun/GetReChargeData',//获取充值列表
				genOrder:'/api/Order/GenOrder', //获取流水号
				getAliPayCfg:'/api/AppFun/GetAliPayCfg', //
				getSign:"/api/AppFun/GetSign",//获取凭证
				getPageWalletLogs:"/api/WalletLog/GetPageWalletLogs",//获取交易记录
			},
			step:0,
			Coins:0, //金币
			lists:[],
			money_index:0, //充值面额
			money_item:{},
			out_trade_no:0, //订单号
			partner:"2088421945009488",
			return_url:"",
			logList:[], //交易记录
		}
	},
	computed:{
		coins_with_unit:function(){
			return this.money_item.Coins+"金币";
		}
	},
	mounted: function() {
		this.getWallet()
		this.getAliPayCfg()
//		this.getPageWalletLogs()
	},
	methods: {
		getAliPayCfg:function(){
			var that = this
			globalData.ajaxPost(that.url.getAliPayCfg,null,function(res){ 
				if(res.suc){
					that.partner = res.data.partner; 
					$("#return_url").val(res.data.alipay_return_url); 
				}
			})
		},
		getWallet:function(){
			var that = this
			globalData.ajaxPost(that.url.getWallet,null,function(res){
				 
				if(res.suc){					
					that.Coins =res.data.Coins;
				}
			})
		},
		select_recharge:function(){
			var that = this
			this.step =1 
			globalData.ajaxPost(that.url.getReChargeData,null,function(res){ 
				if(res.suc){					
					that.lists = res.data; 
					that.money_item = {
						Coins:res.data[0].Coins,
					 	Money:res.data[0].Amount
					}
				}
			})
		},
		select_coin:function(index,item){
			this.money_index = index;
			this.money_item.Coins = item.Coins;
			this.money_item.Money = item.Amount;
		},
		recharge:function(){
			var that = this; 
			var data = {'CargoName':that.money_item.Coins+'金币',
					'CargoNo':'',
					'CargoCount':'1',
					'Money':that.money_item.Coins||0,
					'Remark':'充值'+that.money_item.Money+'元',
					'OrderType':'1'
					}
			globalData.ajaxPost(that.url.genOrder,data,function(res){
				that.out_trade_no = res.data.OrderNo; 
				$("#out_trade_no").val(res.data.OrderNo);
				
				var column = {};
                column.service = $("#service").val();
                column.partner = $("#partner").val();
                column.out_trade_no = $("#out_trade_no").val();
                column.subject = $("#subject").val();
                column.body = $("#body").val();
                column.payment_type = "1";
                column.total_fee = $("#total_fee").val();
                column.seller_id = column.partner;
                column.input_charset = $("#_input_charset").val();
                column.notify_url = $("#notify_url").val();
                column.return_url=$("#return_url").val();
                
				globalData.ajaxPost(that.url.getSign,column,function(res){ 
					if(res.suc){ 
						 $("#sign").val(res.data);
						 document.forms['alipaysubmit'].submit();
					}else{
						alert(res.msg);
					}
				})
			})
		},
		getPageWalletLogs:function(){ //获取交易记录
			var that = this;
			that.step = 3; 
			var req = {PageIndex:1,PageSize:1000}
			globalData.ajaxPost(that.url.getPageWalletLogs,req,function(res){
				console.log(res)
				that.logList = res.data
			})
			
		}
	}
});